<?php
    @header("Content-Type:text/html;charset=utf-8");

    $list = [1,2,[3,4,[5,6,[7,8]]]];

    $userInfo = array("name"=>"张三","age"=>18);

    $goodsList = array(
        array(
            "goodsId"=>"A001",
            "goodsName"=>"Redmi K30",
            "goodsMsg"=>"120Hz流速屏，全速热爱",
            "goodsImg"=>"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2c16238f786e4f93bdb175d7bf21aa47.jpg?thumb=1&w=250&h=250&f=webp&q=90",
            "goodsPrice"=>1559,
            "buyNum"=>1
        ),
        array(
            "goodsId"=>"A002",
            "goodsName"=>"Redmi K30",
            "goodsMsg"=>"120Hz流速屏，全速热爱",
            "goodsImg"=>"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2c16238f786e4f93bdb175d7bf21aa47.jpg?thumb=1&w=250&h=250&f=webp&q=90",
            "goodsPrice"=>1559,
            "buyNum"=>1
        ), 
        array(
            "goodsId"=>"A003",
            "goodsName"=>"Redmi K30",
            "goodsMsg"=>"120Hz流速屏，全速热爱",
            "goodsImg"=>"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2c16238f786e4f93bdb175d7bf21aa47.jpg?thumb=1&w=250&h=250&f=webp&q=90",
            "goodsPrice"=>1559,
            "buyNum"=>1
        ), 
        array(
            "goodsId"=>"A004",
            "goodsName"=>"Redmi K30",
            "goodsMsg"=>"120Hz流速屏，全速热爱",
            "goodsImg"=>"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2c16238f786e4f93bdb175d7bf21aa47.jpg?thumb=1&w=250&h=250&f=webp&q=90",
            "goodsPrice"=>1559,
            "buyNum"=>1
        ), 
        array(
            "goodsId"=>"A005",
            "goodsName"=>"Redmi K30",
            "goodsMsg"=>"120Hz流速屏，全速热爱",
            "goodsImg"=>"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2c16238f786e4f93bdb175d7bf21aa47.jpg?thumb=1&w=250&h=250&f=webp&q=90",
            "goodsPrice"=>1559,
            "buyNum"=>1
        ),
    );

    $str1 =  json_encode($list);
    $str2 =  json_encode($userInfo);
    $str3 =  json_encode($goodsList);

    // json_decode()   将json字符串 转化为 php数组和对象

    $arr1 = json_decode($str1);    //数值数组
    // print_r($arr1);

    $obj1 = json_decode($str2);   // js对象字符串 => php对象
    // print_r($obj1);

    // php对象取值  -> (类似js中的.语法)
    // echo $obj1 -> name;

    $arr3 = json_decode($str3);    //数值数组
    print_r($arr3);

  

?>